package cn.hd01.repository.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

@Entity
@Table(name = "integration")
public class Integration {
	
	@Id
	@GeneratedValue
	private Integer id;
	
	private Integer customerId;
	
	private String customerName;
	
	private BigDecimal usedIntegration;
	
	private BigDecimal integration;
	
	private Date createTime;
	
	private Date updateTime;
	
	@Transient
	private String mobile;
	
	@OneToOne(targetEntity = Customer.class)
	@JoinColumn(name="customerId", referencedColumnName="id", nullable=true, insertable=false, updatable=false)
	@NotFound(action=NotFoundAction.IGNORE)
	private Customer customer;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Integer customerId) {
		this.customerId = customerId;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public BigDecimal getIntegration() {
		return integration;
	}

	public void setIntegration(BigDecimal integration) {
		this.integration = integration;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public BigDecimal getUsedIntegration() {
		return usedIntegration;
	}

	public void setUsedIntegration(BigDecimal usedIntegration) {
		this.usedIntegration = usedIntegration;
	}

	public String getMobile() {
		if(customer != null){
			return customer.getPhoneNo();
		}else{
			return mobile;
		}
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
}
